<template>
	<view>
		<view class="techno-box">
			<view class="video-box">
				<video class="video" :src="params.url" controls></video>
			</view>
			<view class="info-box">
				<view class="info-head">
					<image :src="params.auther_head"></image>
				</view>
				<view class="info-name">
					{{params.auther_name}}
				</view>
			</view>
			<view class="info-title">
				{{params.name}}
			</view>
			<view class="info-info">
				{{params.zan}}&nbsp;点赞|&nbsp;{{params.pl}}&nbsp;评论
			</view>
		</view>
		<view class="save-btn" @click="download">
			保存视频
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				params: {}
			}
		},
		onLoad() {
			this.params = JSON.parse(uni.getStorageSync('video_params'));
		},
		methods: {
			download() {
				let name = encodeURIComponent(this.params.auther_name);
				let url = encodeURIComponent(this.params.url);
				this.$request.get('reptile/douyin/save/' + name + '/' + url, {}).then(res => {

					var downloadTask = uni.downloadFile({
						url: res.url,
						success(res) {
							console.log(res)
							if (res.statusCode === 200) {
								uni.saveVideoToPhotosAlbum({
									filePath: res.tempFilePath,
									success(res) {
										uni.showModal({
											title: '提示',
											content: '保存视频成功',
											showCancel: false
										});
										uni.hideLoading();
									},
									fail(err) {
										uni.showModal({
											title: '提示',
											content: '保存视频失败',
											showCancel: false
										});
										console.log(err)
										uni.hideLoading();
									}
								});
							}
						}
					});
					downloadTask.onProgressUpdate((res) => {
						uni.showLoading({
							title: '保存中...'+res.progress+'%'
						});
					});
				});
			}
		}
	}
</script>

<style lang="less" scoped>
	.techno-box {
		position: relative;

		.video-box {
			width: 100%;

			.video {
				width: 100vw;
				height: 30vh;
			}
		}

		.info-box {
			padding: 0px 5px 5px 10px;
			height: 30px;
			background: #FFFFFF;
			display: flex;
			align-items: center;
			justify-content: flex-start;
			// box-shadow: 1px 2px 5px rgba(0, 0, 0, 0.3);

			.info-head {
				width: 30px;
				height: 30px;

				image {
					width: 30px;
					height: 30px;
					border-radius: 50%;
				}
			}

			.info-name {
				margin-left: 10px;
				font-size: 16px;
			}
		}

		.info-title {
			padding: 5px 5px 5px 10px;
			font-size: 14px;
			font-weight: bold;
			color: #333333;
		}

		.info-info {
			padding: 5px 5px 5px 10px;
			font-size: 12px;
			color: #CCCCCC;
		}
	}

	.save-btn {
		width: 90vw;
		margin-left: 5vw;
		height: 40px;
		border: 0px;
		text-align: center;
		line-height: 40px;
		color: #FFFFFF;
		border-radius: 5px;
		position: absolute;
		bottom: 50px;
		background: linear-gradient(to bottom, #05bd9f, #6a67c7);
	}
</style>
